/**
 * 
 */
package es.cloudcast.server.persistence.dao;

import java.io.Serializable;
import java.util.List;

import es.cloudcast.server.model.BasicModel;
import es.cloudcast.server.persistence.PersistenceException;

/**
 * DAO interface for simple queries
 * 
 * @param T persistence class
 * @param PK Primary key of the persistence class
 * 
 * @see BasicModel
 * @author Samuel García Martínez <in0de>
 *
 */
public interface BasicQueryDAO<T extends BasicModel, PK extends Serializable> {

	/**
	 * Obtains the instance of <T> corresponding given id 
	 * 
	 * @param id PK of the instance
	 * @return the instance of <T> corresponding given id
	 * 
	 * @throws PersistenceException if any error occurs
	 */
	public T get(PK id) throws PersistenceException;
	
	/**
	 * Checks if the instance corresponding to given id exists on the datastore
	 * 
	 * @param id PK of the instance that would be checked
	 * @return <code>Boolean.TRUE</code> if instance exists or <code>Boolean.FALSE</code> if not
	 * 
	 * @throws PersistenceException if any error occurs
	 */
	public Boolean exists(PK id) throws PersistenceException;

	/**
	 * Return all instances of type <T>
	 * 
	 * @return {@link List} of type <T> containing all elements on datastore of that type 
	 * 
	 * @throws PersistenceException if any errors occurs
	 */
	public List<T> getAll() throws PersistenceException;

	/**
	 * Counts all elements of type <T> present on datastore
	 * 
	 * @return the size of elements present on datastore
	 * 
	 * @throws PersistenceException if any error occurs
	 */
	public Integer count() throws PersistenceException;
	
}
